package com.music.muisc.dao;

import com.music.muisc.dto.UnitMusic;
import com.music.muisc.entity.Unit;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UnitRepository extends CrudRepository<Unit, Integer> {
    @Override
     List<Unit> findAll();
    @Query(nativeQuery = true, value = "SELECT u.username,  u.email as email, COUNT(mu.unit_id) as musicCount " +
                    "FROM unit  u left join music_unit  mu ON mu.unit_id = u.unit_id " +
                    "GROUP BY u.username, u.email ORDER BY  3 desc;")
    List<UnitMusic> unitMusics();

}
